﻿using System;
using System.Windows;
using System.Windows.Data;

namespace MoviePlayer.Converters
{
    public class DoubleToTimeSpan : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            if (!(value is double))
                throw new ArgumentException("Value must be a double");
            
            return TimeSpan.FromMilliseconds((double)value);
        }

        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            if (!(value is TimeSpan))
                throw new ArgumentException("Value must be a TimeSpan");

            var temp = (TimeSpan)value;
            return temp.Milliseconds;
        }
    }
}
